#!/bin/bash

export JAVA_HOME=/opt/java/jdk1.8.0_131
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

PID=$(jps -v | grep homework-service-1.0.0.war | grep -v grep | awk '{ print $1 }')
echo "$PID"
if [ -z "$PID" ]
then
    echo Application is already stopped
else
    echo kill $PID
    kill -9 $PID
fi

echo start....

nohup /opt/java/jdk1.8.0_131/bin/java -Xms512m -Xmx512m -Xss256k -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -Xloggc:/opt/gc/homework-service.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/gc/homework-service.dump -Dfile.encoding=UTF-8 -jar /opt/war/homework-service-1.0.0.war --spring.profiles.active=dev > log.file 2>&1 &